class Solution {
public:
   bool isnum(char ch)
    {
        return (ch >= '0' && ch <= '9');
    }
    int myAtoi(string str) {
        int bd = INT_MAX / 10;
        int ans = 0;
        int flg = 1;
        int n = str.size();
        int i = 0;
        while (str[i] == ' ')
            i++;
        if (i == n)
            return ans;
        cout << "1" << endl;
        if (str[i] =='-')
        {
            flg = -1;
            i++;
        }
        else if (str[i] == '+')
        {
            flg = 1;
            i++;
        }
        while (i < n)
        {
            if (!isnum(str[i]))
                break;            
            int x = str[i] -'0';
            if ((ans > bd) || ((ans == bd) && (x > 7)))
                return flg == 1 ? INT_MAX : INT_MIN;
            ans = ans*10 + x; 
            i++;
        }
        cout << "2" << endl;

        return ans*flg;
    }
};